"""
author:mzy
date:2022/10/9
"""
import time
from selenium import webdriver
from selenium.common import NoAlertPresentException
from selenium.webdriver.common.by import By
from selenium.webdriver import ActionChains

def getTimeCode():
        now = time.localtime()
        now_time = time.strftime("%H%M%d", now)
        return now_time



driver = webdriver.Chrome()
driver.get("http://test4.7jft.com/h5/#/pages/login/login")
#设置窗口最大化
driver.maximize_window()

def al():
        try:
                alert = driver.switch_to.alert
                alert.text
                return alert
        except NoAlertPresentException:
                return False
def login(num):
        #获取验证码
        timeCode = getTimeCode()
        timeCode = int(timeCode)

        #验证码登录方式
        driver.find_element(By.XPATH, '//*[@class="uni-scroll-view-content"]/uni-view/uni-view[2]/uni-text/span').click()
        driver.find_element(By.XPATH,'//*[@maxlength="11"]').send_keys(num)
        driver.find_element(By.XPATH,'//*[@maxlength="6"]').send_keys(timeCode)
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[4]/uni-view[3]/uni-button').click()
        # driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[4]/uni-view[3]/uni-button').click()
        #确认
        driver.implicitly_wait(3)
        i=al()
        print(i)
        if i == False:
                driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[1]/uni-view[2]/uni-view/uni-view[2]/uni-view').click()
        else:
               pass

        # 返回首页
        driver.implicitly_wait(3)
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[2]/uni-view').click()
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[2]/uni-view/uni-view[2]/uni-view/uni-view/uni-view[4]/uni-text[1]').click()

        # #场馆
        driver.implicitly_wait(3)
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-tabbar/div[1]/div[3]/div/div[1]/img').click()
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view/uni-view/uni-scroll-view/div/div/div/uni-view/uni-view/uni-view[2]/uni-view/uni-view[1]/uni-view[2]/uni-view[1]/uni-view/uni-image/img').click()
        driver.find_element(By.XPATH, '/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[1]/uni-view[2]/uni-view/uni-scroll-view/div/div/div/uni-view/uni-view/uni-view[2]/uni-view/uni-view[2]/uni-view/uni-view/uni-view[1]/uni-view/uni-view/uni-view/uni-image/img').click()

        #下单
        #余额是否能够满足购买藏品的金额
        driver.find_element(By.XPATH, '/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[1]/uni-view[1]/uni-view[2]/uni-view[3]/uni-view[2]/uni-button').click()
        driver.find_element(By.XPATH, '/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[1]/uni-view[8]/uni-view[2]/uni-view/uni-view[1]/uni-view/uni-view/uni-view[3]/uni-view/uni-view').click()
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view[1]/uni-view[8]/uni-view[2]/uni-view/uni-view[1]/uni-view/uni-view/uni-view[4]/uni-button[2]').click()
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[4]/uni-view/uni-view').click()

        #密码
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[1]/uni-view/uni-view[2]/uni-view/uni-view/uni-view/uni-view[3]/uni-view[1]/uni-view/uni-input/div/input').send_keys(123456)
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[1]/uni-view/uni-view[2]/uni-view/uni-view/uni-view/uni-view[3]/uni-view[2]/uni-button').click()
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[1]/uni-view/uni-view[2]/uni-view/uni-view/uni-view/uni-view[3]/uni-view[2]/uni-button').click()
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[4]/uni-view[2]').click()
        #查看藏品
        # driver.find_element(By.XPATH,'/html/body/uni-app/uni-tabbar/div[1]/div[5]/div/div[1]/img').click()
        r1 = driver.find_element(By.XPATH, "/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view/uni-view/uni-scroll-view/div/div/div/uni-view/uni-view/uni-view[2]/uni-view/uni-view[1]/uni-view[4]/uni-view[2]")
        r2 = driver.find_element(By.XPATH, "/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view/uni-view/uni-scroll-view/div/div/div/uni-view/uni-view/uni-view[2]/uni-view/uni-view[3]/uni-view")
        action = ActionChains(driver)
        driver.implicitly_wait(3)
        action.drag_and_drop(r1, r2).perform()

        #回到顶部
        r2 = driver.find_element(By.XPATH,"/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view/uni-view/uni-scroll-view/div/div/div/uni-view/uni-view/uni-view[2]/uni-view/uni-view[3]/uni-view")
        r1 = driver.find_element(By.XPATH,"/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view/uni-view/uni-scroll-view/div/div/div/uni-view/uni-view/uni-view[2]/uni-view/uni-view[1]/uni-view[3]")
        action = ActionChains(driver)
        driver.implicitly_wait(3)
        action.drag_and_drop(r2, r1).perform()

        #设置-退出登录
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view/uni-view/uni-scroll-view/div/div/div/uni-view/uni-view/uni-view/uni-view/uni-view[1]/uni-view[1]/uni-view/uni-image/img').click()
        r1 = driver.find_element(By.XPATH,"/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view[1]/uni-view")
        r2 = driver.find_element(By.XPATH,"/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view[8]/uni-view")
        action = ActionChains(driver)
        driver.implicitly_wait(3)
        action.drag_and_drop(r1, r2).perform()
        driver.find_element(By.XPATH,'/html/body/uni-app/uni-page/uni-page-wrapper/uni-page-body/uni-view/uni-view/uni-view[3]/uni-view[9]').click()

login(18811603783)

